home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
10,000 Great Games
/
10,000 Great Games.iso
/
Product
/
66
/
data1.cab
/
Source_Files
/
Src
/
Player.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
2000-01-16
|
4KB
|
184 lines
#include "stdafx.h"
#include <string.h>
int names_visible = FALSE, no_armor = FALSE;
cPlayer *players = 0, *first_at_end;
char pl_name[kMaxPlayers][16];
int pl_selected[kMaxPlayers];
void cPlayer::make()
{
// Make players
cProperties *p = cProperties::find_first("PLAYER");
if (pl_selected[0] && p != 0)
{
new cPlayer (p, pl_name[0], new cKeyboard(0));
p = cProperties::find_next();
if (!p) p = cProperties::find_first("PLAYER");
}
if (pl_selected[1] && p != 0)
{
new cPlayer (p, pl_name[1], new cKeyboard(1));
p = cProperties::find_next();
if (!p) p = cProperties::find_first("PLAYER");
}
if (pl_selected[2] && p != 0)
{
new cPlayer (p, pl_name[2], new cKeyboard(2));
p = cProperties::find_next();
if (!p) p = cProperties::find_first("PLAYER");
}
if (pl_selected[3] && p != 0)
{
new cPlayer (p, pl_name[3], new cMouse);
p = cProperties::find_next();
if (!p) p = cProperties::find_first("PLAYER");
}
if (pl_selected[4] && p != 0)
{
new cPlayer (p, pl_name[4], new cJoystick(0));
p = cProperties::find_next();
if (!p) p = cProperties::find_first("PLAYER");
}
if (pl_selected[5] && p != 0)
{
new cPlayer (p, pl_name[5], new cJoystick(1));
p = cProperties::find_next();
if (!p) p = cProperties::find_first("PLAYER");
}
if (pl_selected[6] && p != 0)
{
new cPlayer (p, pl_name[6], new cJoystick(2));
p = cProperties::find_next();
if (!p) p = cProperties::find_first("PLAYER");
}
if (pl_selected[7] && p != 0)
{
new cPlayer (p, pl_name[7], new cJoystick(3));
p = cProperties::find_next();
if (!p) p = cProperties::find_first("PLAYER");
}
}
cPlayer::cPlayer(cProperties *_orig, const char *_name, cController *c)
: cCharacter(_orig)
{
add_end((cList **)&players);
// Setup controller
controller = c;
controller->reset();
// Put player in bubble
new cBubble(CHAR_VBUBBLE + rnd(CHAR_RVBUBBLE), this);
// For clarity show name
name = strdup(_name);
set_text_above(name, 4 * sec);
// Setup score system
score = 0;
hit_counter = 0;
scorelist = 0;
new cScore(this);
}
cPlayer::~cPlayer()
{
free(name);
delete controller;
scorelist->delete_list();
}
int cPlayer::control()
{
// Do movement/animation etc
if (!cCharacter::control())
{
// Revive player
revive();
// Reset controller
controller->reset();
// Put player in bubble
new cBubble(CHAR_VBUBBLE + rnd(CHAR_RVBUBBLE), this);
// Show name for clarity
set_text_above(name, 3 * sec);
}
// Names always visible?
if (names_visible && *get_text_above() == 0)
set_text_above(name, 4 * sec);
// Check end level
if (y > surface->total_h && first_at_end == 0)
{
first_at_end = this;
modify_score(100);
cScore::determine_winner();
}
// Control character
controller->determine(this);
return TRUE;
}
void cPlayer::hit(int armor_power)
{
cCharacter::hit(no_armor && armor_power > 0? 1000:armor_power);
}
void cPlayer::modify_score(int delta_score, cGameObject *who)
{
// Count score
score += delta_score;
// We're only interested in other player objects
if (dynamic_cast<cPlayer *>(who) == 0)
return;
// Keep who we hit
for (cScoreList *l = scorelist; l != 0 && l->who != who; l = (cScoreList *)l->next);
if (l != 0)
l->score += delta_score;
else
new cScoreList(&scorelist, delta_score, who);
// Increase hit counter
hit_counter++;
}